#include<stdio.h>
int main(){
	int t;
	char c;
	int a,b;
	scanf("%d",&t);
	for(int i=1;i<=t;i++){
	scanf("%x%c%x",&a,&c,&b);
	if(c == '+'){
	printf("%o\n",a+b);
	}else{printf("%o\n",a-b);}}
	return 0;
}
